package com.easytake.emotioncat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easytake.emotioncat.constant.NumberConstants;
import com.easytake.emotioncat.entity.EmDictionaryEntity;
import com.easytake.emotioncat.mapper.EmDictionaryMapper;
import com.easytake.emotioncat.service.IEmDictionaryService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-10-27
 */
@Service
public class EmDictionaryServiceImpl extends ServiceImpl<EmDictionaryMapper, EmDictionaryEntity> implements IEmDictionaryService {

    @Override
    public List<EmDictionaryEntity> getListByType(Integer type) {
        if (Objects.equals(type, NumberConstants.ZERO)) {
            return this.list();
        }
        QueryWrapper<EmDictionaryEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmDictionaryEntity::getType, type);
        return this.list(queryWrapper);
    }

    @Override
    public Boolean exist(String vals, Integer type) {
        QueryWrapper<EmDictionaryEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmDictionaryEntity::getVals, vals).eq(EmDictionaryEntity::getType, type);
        List<EmDictionaryEntity> entityList = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(entityList)) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }
}
